<template>
  <div id="app" class="application">
    <Console v-if="consoled()"></Console>
    <router-view v-else-if="public()"></router-view>
  </div>
</template>

<script>
  import Console from '@/views/console'
  export default {
    name: 'App',
    components: { Console },
    created() {
      this.$md.setLoginTimeout(() => {
        this.$storage.delUser()
        this.$Message.warning({
          content: this.$t('server.notlogin'),
          onClose: () => {
            window.location.href = '/#/login'
          },
        })
      })
      if (!this.$storage.checkLogin()) window.location.href = '/#/login'
    },
    methods: {
      consoled() {
        let user = this.$storage.getUser()
        if (user != null && !this.public()) {
          this.$md.setToken(user.token)
          return true
        }
        return false
      },
      public() {
        return !!this.$route.meta.public
      }
    }
  }
</script>
